# -*- coding: utf-8 -*-

# Scrapy settings for car58 project

import sys, os
reload(sys)
sys.setdefaultencoding('utf-8')
from conf import read_json_file

SETTINGS = read_json_file()

SPIDER_NAME = SETTINGS['Spider_Name']
GLOBAL_SETTINGS = SETTINGS['Global_Settings']
SPIIDER_SETTINGS = SETTINGS['Spider_Settings']
ITEM_ORDER = SETTINGS['Item_Order']
ITEMS_DEFINE = SETTINGS['Item_Define']
REDIS_SETTINGS = SETTINGS['Redis_Settings']
STORE_SETTINGS = SETTINGS['Store_Settings']

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))

BOT_NAME = 'car58'

SPIDER_MODULES = ['car58.spiders']
NEWSPIDER_MODULE = 'car58.spiders'

DEPTH_LIMIT = 1

DOWNLOAD_TIMEOUT = 10

# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'car58 (+http://www.yourdomain.com)'

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS=32

# Configure a delay for requests for the same website (default: 0)
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 0.5
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN=16
#CONCURRENT_REQUESTS_PER_IP=16

# Disable cookies (enabled by default)
COOKIES_ENABLED=False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED=False

# Override the default request headers:
DEFAULT_REQUEST_HEADERS = {
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'Accept-Language': 'zh-CN,zh;q=0.8',
}

# Enable or disable spider middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'car58.middlewares.MyCustomSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
   'car58.middlewares.rotate_useragent.RotateUserAgentMiddleware': 543,
}

# Enable or disable extensions
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
   'car58.pipelines.MySQLPipeline': 300,
}


# MongoDB
MONGO_URI = 'mongodb://localhost:27017'
MONGO_SERVER = 'localhost'
MONGO_PORT = 27017
MONGO_DB = 'easyspider'
MONGO_COLLECTION = 'car58'

# MySQLDB
MYSQL_HOST = 'localhost'
MYSQL_PORT = 3306
MYSQL_DB = 'easyspider'
MYSQL_USER = 'root'
MYSQL_PWD = '35535'
